package com.example.commen.base.dialoglib;


import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.example.commen.R;
import com.example.commen.utile.CommonUtils;


/**
 * 进度dialog,仿照IOS样式
 */
public class ProgressDialog extends AlertDialog {


    private boolean outIsHind = false;
    private boolean isok = false;
    private String message;

    private ProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    public ProgressDialog(Context context, String message){
        this(context,message,false);
    }
    public ProgressDialog(Context context, String message,boolean outIsHind,boolean isok){
        this(context, com.qmuiteam.qmui.R.style.QMUI_BottomSheet);
        this.message=message;
        this.outIsHind=outIsHind;
        this.isok=isok;
    }
    public ProgressDialog(Context context, String message, boolean outIsHind){
        this(context, com.qmuiteam.qmui.R.style.QMUI_BottomSheet);
        this.message=message;
        this.outIsHind=outIsHind;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_progress_dialog);
        initView();
    }

    private void initView() {

        TextView tv_progressDialog =  findViewById(R.id.tv_progressDialog);
        tv_progressDialog.setText(message);
        if(TextUtils.isEmpty(message)){
            tv_progressDialog.setVisibility(View.GONE);
        }
        if(isok){
            findViewById(R.id.progress).setVisibility(View.GONE);
            findViewById(R.id.progressok).setVisibility(View.VISIBLE);
        }
        setCancelable(true);
        this.setCanceledOnTouchOutside(outIsHind);
        //设置其大小
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = CommonUtils.getScreenHeight();
        window.setAttributes(lp);
//        RequestOptions options =new RequestOptions().placeholder(R.drawable.load);
//        Glide.with(CommonUtils.getContext()).load(R.drawable.load).apply(options).into(progress);
    }
}
